home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / GRAPH_FO / (GRAPH / CGRAPHTE / CGRAPHAP.C next >
Text File  |  1991-02-15  |  9KB  |  267 lines

  1. /******************************************************************************
  2.  CGraphApp.c
  3.  
  4.                             The GraphApp Class
  5.  
  6.     SUPERCLASS =  CApplication.c
  7.  
  8.     Copyright ⌐ 1991 Maarten Meijer. All rights reserved.
  9.         CIS 100016,1764; FidoNet 2:512/114
  10. *******************************************************************************/
  11.  
  12. /* includes */
  13. #include <Global.h>
  14. #include <Commands.h>
  15. #include <CFWDesktop.h>
  16. #include <CBartender.h>
  17.  
  18. #include "GraphCommands.h"
  19. #include "CGraphApp.h"
  20. #include "CGraphDoc.h"
  21.  
  22. /* externs */
  23. extern CBartender    *gBartender;
  24. extern CDesktop        *gDesktop;            /* The visible Desktop                */
  25. extern OSType        gSignature;            /* Creator for Application's files    */
  26.  
  27. CursHandle    gCrossCursor;
  28. CursHandle    gGrabCursor;
  29.  
  30. /* methods */
  31. /******************************************************************************
  32.  IGraphApp
  33.  
  34.         Initialize a GraphApp object
  35.  ******************************************************************************/
  36.  
  37. void    CGraphApp::IGraphApp()
  38. {
  39.                                         /* Initialize superclass            */
  40.  
  41.         /* $$$ Parameters are the number of times to call MoreMasters,    */
  42.         /* the number of bytes of heap space to reserve for monitoring    */
  43.         /* low memory situations, and credit limit for memory requests.    */
  44.         /*   Four (4) is a reasonable number of MoreMasters() calls,    */
  45.         /* but you should determine a good number for your application    */
  46.         /* by observing the heap using an object code debugger such as    */
  47.         /* TMON or Macsbug. Set this parameter to zero, give your        */
  48.         /* program a rigorous work-out, then look at the heap and count    */
  49.         /* how many master pointer blocks have been allocated. Master    */
  50.         /* pointer blocks are nonrelocatable and have a size of 0x100    */
  51.         /* (hex). You should call MoreMasters() at least this many        */
  52.         /* times -- add a few extra just to be safe. The purpose of all    */
  53.         /* this preflighting is to prevent heap fragmentation. You        */
  54.         /* don't want the Memory Manager to call MoreMasters() and        */
  55.         /* create a nonrelocatable block in the middle of your heap. By    */
  56.         /* calling MoreMasters() at the very beginning of the program,    */
  57.         /* you ensure that these blocks are allocated in a group at the    */
  58.         /* bottom of the heap.                                            */
  59.         /*   The memory reserve is a safeguard for handling low memory    */
  60.         /* conditions and is used by the GrowMemory() method in            */
  61.         /* CApplication (check there for more comments). In general,    */
  62.         /* your program should never request a memory block greater        */
  63.         /* than this reserve size without explicitly checking in        */
  64.         /* advance whether there is enough free memory to satisfy the    */
  65.         /* the request.                                                    */
  66.         /*   The credit limit specifies a cut-off level for memory        */
  67.         /* requests which can tap the memory reserve. Requests larger    */
  68.         /* than this size will not use the memory reserve when the        */
  69.         /* system pleads for more memory.                                */
  70.  
  71.     CApplication::IApplication(10, 20000L, 2000L);
  72.  
  73.                 /* &&& Initialize global variables defined by your    */
  74.                 /*     application and the instance variables of    */
  75.                 /*     your Application subclass.                    */
  76.     gCrossCursor = GetCursor(crossCursor);
  77.     gGrabCursor = GetCursor(9);
  78.  
  79. }
  80.  
  81. /******************************************************************************
  82.  SetUpFileParameters {OVERRIDE}
  83.  
  84.         Set parameters used by the Standard File Package
  85.  ******************************************************************************/
  86.  
  87. void    CGraphApp::SetUpFileParameters()
  88. {
  89.     inherited::SetUpFileParameters();    /* Use defaults from superclass        */
  90.  
  91.         /* &&& Specify file parameters for the Application */
  92.  
  93.     gSignature = 'Graf';                /* XXX Specify a four-character        */
  94.                                         /*   signature for your application    */
  95.  
  96.     sfNumTypes = 1;                        /* XXX Specify the number and types    */
  97.     sfFileTypes[0] = 'Graf';            /*   of files recognized. This app    */
  98.                                         /*   opens pictures and paintings.    */
  99. }
  100.  
  101.  
  102. /******************************************************************************
  103.  SetUpMenus {OVERRIDE}
  104.  
  105.         Set up menus which must be created at run time, such as a
  106.         Font menu. You can eliminate this method if your application
  107.         does not have any such menus.
  108.  ******************************************************************************/
  109.  
  110. void    CGraphApp::SetUpMenus()
  111. {
  112.     inherited::SetUpMenus();            /* Superclass takes care of adding    */
  113.                                         /*   menus specified in a MBAR id=1    */
  114.                                         /*   resource                        */
  115.  
  116.         /* &&& Code for creating run-time menus    */
  117.     /*    gBartender->InsertHierMenu(MENUsize, cmdSize, MENUlayout, 1); */
  118.  
  119.     AddResMenu(GetMHandle(MENUfont), 'FONT');
  120.  
  121.     gBartender->SetDimOption(MENUfont, dimNONE);
  122.     gBartender->SetDimOption(MENUsize, dimNONE);
  123.  
  124.         /**
  125.          **    For Font and Size menus, one of the items
  126.          **    is always checked. Setting the unchecking option
  127.          **    to TRUE lets the bartender know that it should
  128.          **    uncheck all the menu items because an UpdateMenus()
  129.          **    method will check the right items.
  130.          **    For the Style menu, uncheck all the items and
  131.          **    let the edit pane's UpdateMenus() method check the
  132.          **    appropriate ones.
  133.          **
  134.          **/
  135.  
  136.     gBartender->SetUnchecking(MENUfont, TRUE);
  137.     gBartender->SetUnchecking(MENUsize, TRUE);
  138. }
  139.  
  140.  
  141. /******************************************************************************
  142.  DoCommand {OVERRIDE}
  143.  
  144.         Execute a command
  145.  
  146.         $$$ Command numbers are longs, where command numbers 1 - 1023
  147.             are reserved, 0 is a special flag indicating a nonexistant
  148.             command (sort of like a NOP), and negative numbers indicate
  149.             a command which was added at run time (the high word is
  150.             the negative of the MENU id, and the low word is the item
  151.             number within that menu).
  152.  
  153.             It's important to pass along commands not handled by this
  154.             class to the inherited DoCommand method. These commands
  155.             will be handled by the THINK Class Library in a default manner.
  156.  ******************************************************************************/
  157.  
  158. void    CGraphApp::DoCommand(
  159.     long        theCommand)
  160. {
  161.     switch (theCommand) {
  162.  
  163.         /* &&& Cases for commands handled by your application */
  164.  
  165.         default:                        /* Invoke inherited method to        */
  166.                                         /*   handle other commands            */
  167.             inherited::DoCommand(theCommand);
  168.             break;
  169.  
  170.     }
  171. }
  172.  
  173.  
  174. /******************************************************************************
  175.  UpdateMenus {OVERRIDE}
  176.  
  177.         Perform menu management tasks
  178.  ******************************************************************************/
  179.  
  180. void    CGraphApp::UpdateMenus()
  181. {
  182.     inherited::UpdateMenus();            /* Enable standard commands            */
  183.  
  184.         /* &&& Enable the commands handled by your Application class    */
  185. }
  186.  
  187.  
  188. /******************************************************************************
  189.  Exit {OVERRIDE}
  190.  
  191.         Program is about to terminate. Last chance to clean up.
  192.  
  193.         $$$ Here's the place to delete temporary files or to automatically
  194.             save settings. However, most applications don't need to do
  195.             anything here and can elimate this method.
  196.  ******************************************************************************/
  197.  
  198. void    CGraphApp::Exit()
  199. {
  200.         /* &&& Exit code for your application */
  201. }
  202.  
  203.  
  204. /******************************************************************************
  205.  CreateDocument {OVERRIDE}
  206.  
  207.         Make a document. This message is sent when the user chooses the
  208.         "New" command.
  209.  ******************************************************************************/
  210.  
  211. void    CGraphApp::CreateDocument()
  212. {
  213.     CGraphDoc    *theDocument;
  214.  
  215.                                     /* Create and initialize a Document        */
  216.  
  217.                                     /* $$$ Passing "this" to IGraphDoc    */
  218.                                     /*   means that the Application object    */
  219.                                     /*   is the supervisor of the Document    */
  220.     theDocument = new(CGraphDoc);
  221.     theDocument->IGraphDoc(this);
  222.  
  223.     theDocument->NewFile();            /* Tell Document to make a new file        */
  224.  
  225.                                     /* $$$ Document is responsible for        */
  226.                                     /*   do whatever's necessary to set up    */
  227.                                     /*   a new file (e.g., displaying a        */
  228.                                     /*   blank window)                        */
  229. }
  230.  
  231.  
  232. /******************************************************************************
  233.  OpenDocument {OVERRIDE}
  234.  
  235.         Open an existing file and create a document object for displaying
  236.         information. This message is sent when the user chooses the
  237.         "Open..." command or when the application was launched by
  238.         double-clicking on a file or selecting file(s) and choosing
  239.         "Open" from the Finder.
  240.  
  241.         The macSFReply parameter is a record which contains information
  242.         about the file to open (name, volume number, etc.).
  243.  ******************************************************************************/
  244.  
  245. void    CGraphApp::OpenDocument(
  246.     SFReply        *macSFReply)        /* Standard File reply record            */
  247. {
  248.     CGraphDoc    *theDocument;
  249.  
  250.                                     /* Create and initialize a Document        */
  251.  
  252.                                     /* $$$ Passing "this" to IGraphDoc    */
  253.                                     /*   means that the Application object    */
  254.                                     /*   is the supervisor of the Document    */
  255.     theDocument = new(CGraphDoc);
  256.     theDocument->IGraphDoc(this);
  257.  
  258.                                     /* Tell Document to open the file.        */
  259.  
  260.                                     /* $$$ The Document is responsible for    */
  261.                                     /*   creating whatever windows are        */
  262.                                     /*   necessary to display the file and    */
  263.                                     /*   actually reading the contents of    */
  264.                                     /*   the file from disk                    */
  265.     theDocument->OpenFile(macSFReply);
  266. }
  267.